//接口对json的约束
interface Product{
    title:string,
    price:number|boolean,
    intro?:string,  //可选属性
    [propName:string]:any  //添加任意属性
}

let product:Product = {title:'面包',price:12,intro:'豆沙'};

let productList:Product[] = [
    {title:'面包1',price:12,intro:'豆沙'},
    {title:'面包2',price:1},
    {title:'香蕉',price:11,oldPrice:7,type:'进口'}
];


//接口对函数的约束

interface CompareInter{
    (num1:number,num2:number):boolean
}

// function compare(num1:number,num2:number):boolean{
//     return num1>num2
// }

let compare:CompareInter = (num1,num2) => {
    return num1>num2
}

compare(2,1)

//接口对类的约束  implements

interface AnimalInter{
    name:string,
    eat:(food:string)=> void
}

class Cat implements AnimalInter{
    name:string;
    constructor(name:string){
        this.name = name
    }
    eat(food:string){
        console.log(this.name + '吃' +food);
    }
}

let cat = new Cat('小猫')

cat.eat('鱼')

